/**
  ETFAna project, Anyang Normal University && IMP-CAS
  \brief solve DC position and angles from four certain sampling point - four
  laser ball connectors inserted in the pin holes of the DCs
  \note intended for internal use (meant for the developers) only
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2023-10-18
  \date 2023-10-19 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2023-10-18   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#include <string>
#include <iostream>
#include "ETFMath.h"
#include "ETFYaml.h"

using std::string;
using std::cout;
using std::endl;

static const string posconfig = "../etfana/config/apr2023/doc/pos.yaml";
// static const string posconfig = "pos.yaml";

int main(){
  const ETFYaml cc(posconfig);
  double pos[3]{}, ang[3]{};
  double a[3]{}, b[3]{}, c[3]{}, d[3]{};
  if(!cc["pos"]){
    cout << "illegal yaml file: pos not defined";
    exit(1);
  } // end if

  cout << "# ----- Position (in mm) and Orientation (in deg) of the DCs -----";
  cout << endl << endl;
  for(const auto &p : cc["pos"]){
    const string name = p["name"].as<string>();
    const bool isDC1 = name == "dc1";
    for(int i = 3; i--;){
      a[i] = p["a"][i].as<double>();
      b[i] = p["b"][i].as<double>();
      c[i] = p["c"][i].as<double>();
      d[i] = p["d"][i].as<double>();
    } // end for
    ETFMath::Pos(pos, ang, a, b, c, d, isDC1);
    // output the result
    cout << name << ":" << endl;
    cout << "  pos: [" << pos[0] << ", " << pos[1] << ", " << pos[2] << "]\n";
    cout << "  ang: [" << ang[0] << ", " << ang[1] << ", " << ang[2] << "]";
    cout << endl << endl;
  } // end for over dcs

  return 0;
} // end main function








// {
    // calculate distance of 2 parallel planes //
  // // no laser ball
  // const double a0[3] = {833.15, 159.33, 5044.57};
  // const double b0[3] = {837.36,  48.07, 5039.87};
  // const double c0[3] = {1790.13, 353.15, 4789.92};
  // const double d0[3] = {1793.48, -7.94, 4788.95};
  // // with laser ball
  // const double a1[3] = {968.19, 383.19, 5005.84};
  // const double b1[3] = {1651.12, 388.05, 4824.11};
  // const double c1[3] = {971.12, -367.34, 4998.32};
  // const double d1[3] = {1655.17, -361.33, 4817.24};

  // const double a0[3] = {1., 0., 0.};
  // const double b0[3] = {0., 1., 0.};
  // const double c0[3] = {0., 0., 1.};
  // const double a1[3] = {2., 0., 0.};
  // const double b1[3] = {0., 2., 0.};
  // const double c1[3] = {0., 0., 2.};

  // double dd = 0., dd1 = 0.;
  // double n0[3]{}, n1[3]{}; // the normal vector
  // static const double DPAT = 25.4; // 
  // ETFMath::Plane(n0, a0, b0, d0);
  // ETFMath::Plane(n1, a1, b1, c1);
  // dd = ETFMath::PlaneDistance(n0, n1) + DPAT;
  // dd1 += dd;
  // cout << "dd0: " << dd << "mm" << endl;
  // ETFMath::Plane(n0, a0, b0, d0);
  // ETFMath::Plane(n1, a1, b1, d1);
  // dd = ETFMath::PlaneDistance(n0, n1) + DPAT;
  // dd1 += dd;
  // cout << "dd1: " << dd << "mm" << endl;
  // ETFMath::Plane(n0, a0, b0, d0);
  // ETFMath::Plane(n1, a1, c1, d1);
  // dd = ETFMath::PlaneDistance(n0, n1) + DPAT;
  // dd1 += dd;
  // cout << "dd2: " << dd << "mm" << endl;
  // ETFMath::Plane(n0, a0, b0, d0);
  // ETFMath::Plane(n1, b1, c1, d1);
  // dd = ETFMath::PlaneDistance(n0, n1) + DPAT;
  // dd1 += dd;
  // cout << "dd3: " << dd << "mm" << endl;
  // dd1 /= 4.; 
  // cout << "distance: \033[1m" << dd1 << "\033[0mmm" << endl;

// }